package com.itheima.loop;

public class ForDemo2 {
    public static void main(String[] args) {
        int result =test1(5);
    }

    public static int test1(int n) {    //求1到n的和
        int sum = 0;
        for (int i = 1; i <=n ; i++) {
            sum=sum+i;
        }
        System.out.println("1到" + n + "的和是" + sum);
        return sum;
    }
}
